package com.example.home.rubbish.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.bumptech.glide.Glide;
import com.example.home.R;
import com.example.home.rubbish.bean.NewsClassifyDetailBean;
import com.example.home.tool.OKHttpTool;

import static com.example.home.tool.StaticActi.ip;

public class NewsClassifyDetailActivity extends AppCompatActivity {

    private ImageView back;
    private ImageView imgUrl;
    private TextView introduce;
    private TextView guide;
    private String classify;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_news_classify_detail);
        Intent intent = getIntent();
        classify =intent.getStringExtra("classify");
        initView();
        showToast();
    }

    private void showToast() {
        OKHttpTool.doNetRequest("prod-api/api/garbage-classification/garbage-classification/list?pageNum=1&pageSize=10&name="+classify,
                OKHttpTool.GET,
                NewsClassifyDetailBean.class,
                new OKHttpTool.NetCallback() {
                    @Override
                    public void onSuccess(Object obj) {
                        NewsClassifyDetailBean newsClassifyDetailBean = (NewsClassifyDetailBean) obj;
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                Glide.with(NewsClassifyDetailActivity.this).load(ip+newsClassifyDetailBean.getRows().get(0).getImgUrl()).into(imgUrl);
                                introduce.setText(newsClassifyDetailBean.getRows().get(0).getIntroduce());
                                guide.setText(newsClassifyDetailBean.getRows().get(0).getGuide());
                            }
                        });
                    }

                    @Override
                    public void onFailure(String msg) {

                    }
                });
    }

    private void initView() {


        back = findViewById(R.id.back);
        imgUrl = findViewById(R.id.imgUrl);
        introduce = findViewById(R.id.introduce);
        guide = findViewById(R.id.guide);

        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                NewsClassifyDetailActivity.this.finish();
            }
        });

    }
}